import Taro from '@tarojs/taro'
import app from '../../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            topicss: {
                offset: 0,
                length: 25,
                items: []
            },
        };
        return this.state;
    },
    listTopics() {
        var me = this;
        var data = {offset: me.state.topicss.offset, length: me.state.topicss.length};
        app.get("web/dynamic_topic/topicList", data, function(res) {
            var topics = me.state.topicss;
            var list = res.data.result.list;
            topics.items = topics.items.concat(list);
            me.setState({
                total: res.data.result.total,
                topicss: topics
            });
        });
        
    },
    componentWillMount () {
        if(this.init) {
            this.init();
        }
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = v;
        this.setState({n: temp[names[i]]});
    },
    handleTextareaChange(name, e) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        temp[names[i]] = e.target.value;
        this.setState({n: temp[names[i]]});
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
